package com.fz.controller.merchant;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fz.aop.login.AnonymousAccess;
import com.fz.beans.PageBeans;
import com.fz.common.ResponseEntity;
import com.fz.dto.merchant.merDept.MerDeptAdd;
import com.fz.dto.merchant.merDept.MerDeptQuery;
import com.fz.dto.merchant.merDept.MerDeptUpd;
import com.fz.entity.merchant.MerDept;
import com.fz.entity.merchant.MerUser;
import com.fz.security.utils.SecurityUtils;
import com.fz.service.merchant.MerDeptService;
import com.fz.vo.merchant.merDept.MerDeptVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiSort;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(tags = "部门管理")
@RequestMapping("/merDept")
@ApiSort(value = 5)
@SuppressWarnings("unchecked")
public class MerDeptController {

    @Resource
    private MerDeptService merDeptService;

    @GetMapping("/findMerDeptList")
    @ApiOperation(value = "分页查询部门列表")
    @ApiOperationSupport(order = 1)
    @AnonymousAccess
    public ResponseEntity<IPage<MerDeptVo>> findMerDeptList(MerDeptQuery merDeptQuery, PageBeans pageBeans) throws Exception{
        return merDeptService.findMerDeptList(merDeptQuery,pageBeans.getPageNum(),pageBeans.getPageSize());
    }

    @PostMapping("/addMerDept")
    @ApiOperation(value = "新增部门")
    @ApiOperationSupport(order = 2)
    public ResponseEntity addMerDept(@RequestBody MerDeptAdd merDeptAdd) throws Exception{
        return merDeptService.addMerDept(merDeptAdd);
    }

    @PostMapping("/updateMerDept")
    @ApiOperation(value = "修改部门")
    @ApiOperationSupport(order = 3)
    public ResponseEntity updateMerDept(@RequestBody MerDeptUpd merDeptUpd) throws Exception{
        return merDeptService.updateMerDept(merDeptUpd);
    }

    @GetMapping("/findMerDeptInSelect")
    @ApiOperation(value = "部门下拉框")
    @ApiOperationSupport(order = 4)
    public ResponseEntity<List<MerDept>> findMerDeptInSelect() throws Exception{
        return merDeptService.findMerDeptInSelect();
    }

}
